﻿//Hello Project Imperium Members!
using Newtonsoft.Json.Linq;
using System;
using XbmcManager.Modules;

namespace XbmcManager
{
    public class XbmcController
    {
        internal XbmcConnection connection;
        public XbmcPlayer Player;
        public XbmcApplication Application;
        public XbmcLauncher Launcher;
        public XbmcMuteManager SoftMuter;
        public XbmcGui GUI;
        public XbmcVideoLibrary VideoLibrary;

        /// <summary>
        /// Private Constructor for XbmcController class
        /// </summary>
        public XbmcController(
            String IpAddress,
            int PortNumber,
            String UserName,
            String Password)
        {
            this.connection = new XbmcConnection(IpAddress, PortNumber, UserName, Password);
            this.Player = new XbmcPlayer(this, this.connection);
            this.Application = new XbmcApplication(this, this.connection);
            this.Launcher = new XbmcLauncher();
            this.SoftMuter = new XbmcMuteManager(this);
            this.GUI = new XbmcGui(this, this.connection);
            this.VideoLibrary = new XbmcVideoLibrary(this, this.connection);
        }

        /// <summary>
        /// Navigation Controls
        /// </summary>
        public void NavHome()
        {
            this.connection.SendJson("Input.Home");
        }

        public void NavBack()
        {
            this.connection.SendJson("Input.Back");
        }
        
        public void NavLeft()
        {
            this.connection.SendJson("Input.Left");
        }
        
        public void NavRight()
        {
            this.connection.SendJson("Input.Right");
        }
        
        public void NavDown()
        {
            this.connection.SendJson("Input.Down");
        }
        
        public void NavUp()
        {
            this.connection.SendJson("Input.Up");
        }
        
        public void Select()
        {
            this.connection.SendJson("Input.Select");
        }

        internal static bool isError(JObject jsonResponse)
        {
            return (jsonResponse == null || jsonResponse["error"] != null);
        }
    }
}